import api from "@/utils/api";
import {objToFormData} from "@/utils";

export interface UserInfo {
    username: string;
    password: string;
    avatar?: File | string;
    account: string;
    type: '0' | '1';    // 1管理员 0学生
    confirmPassword?: string;
}

export function createUserApi(userInfo: UserInfo) {
    return api.post('/user', objToFormData(userInfo));
}

export function updateUserApi(userInfo: UserInfo,id: number) {
    if (!(userInfo.avatar instanceof File)) delete userInfo.avatar;
    return api.put('/user', objToFormData(userInfo),{
        params: {id}
    });
}

export function getUserApi(pageInfo: { pageSize: number; pageIndex: number; }) {
    return api('/user', {
        params: pageInfo
    })
}

export function delUser(id: number) {
    return api.delete('/user', {
        params: {id}
    })
}
export function registerApi(data: any){
    return api.post('/user/register', objToFormData(data));
}